
import {everyDayNew,canttenId} from "../../../http/api"
const app = getApp()


Page({
  data: {
    goodsArr:[],
    merchantId:wx.getStorageSync('merchantId') 
  },

  checkIsLogin(){
    if(!wx.getStorageSync('openid') ||  !wx.getStorageSync('id')){
      wx.navigateTo({
        url: '/pages/user/authorize/index',
      })
    }

  },

  toPage(e){
    app.checkIsLogin()
    const {url} = e.currentTarget.dataset
    wx.redirectTo({
      url
    })
    
  },





  async getData(){
    wx.showLoading()
    let  merchantId = this.data.merchantId
    if(!merchantId){
      const res = await canttenId()
      console.log(res)
      if(res.data.code === 200){
        merchantId = res.data.data
        this.setData({
          merchantId
        })
        wx.setStorageSync('merchantId', merchantId)
      }
    }
    
    everyDayNew({merchantId}).then(res=>{

      if(res.data.code === 200){
        this.setData({
          goodsArr:[...res.data.data]
        })

      }

    }).finally(()=>{
      wx.hideLoading()
    })
  },

  onLoad(){
    this.getData()
    // this.setData({
    //   merchantId:wx.getStorageSync('merchantId')
    // })
  }
  
})
